import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mtf/app/data/UsdRecordEntity.dart';
import 'package:mtf/app/modules/transaction_record_module/transaction_record_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';
import 'package:mtf/app/widget/SettingBar.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../../R.dart';
import '../../utils/AppUtils.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class transaction_recordPage extends GetView<transaction_recordController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarLeftTitle(title: "交易记录"),
      body: RefreshConfiguration(
        headerBuilder: () => ClassicHeader(),
        footerBuilder: () => ClassicFooter(),
        child: SmartRefresher(
          enablePullDown: true,
          enablePullUp: true,
          onRefresh: () {
            controller.refreshData();
          },
          onLoading: () {
            controller.loadData();
          },
          controller: controller.refreshController,
          child: Obx(() {
            return ListView.builder(
              itemBuilder: (context, index) {
                return itemChange(controller.usdList[index]);
              },
              shrinkWrap: true,
              itemCount: controller.usdList.length,
              physics: NeverScrollableScrollPhysics(),
            );
          }),
        ),
      ),
    );
  }

  Widget itemChange(ListUSDElement bean) {
    return Container(
      margin: EdgeInsets.only(bottom: 10, left: 10, right: 10),
      padding: EdgeInsets.only(left: 10, right: 10, bottom: 15),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(10)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          SettingBar(
              leftText: bean.actionTxt ?? "",
              paddingHorizontal: 0,
              leftIconSpace: 0,
              rightIconSpace: 0,
              rightText: "订单号：${bean.order ?? ""}",
              rightTextColor: c_666666,
              rightTextSize: 12,
              backgroupColor: Colors.transparent,
              showDivider: true),
          SizedBox(
            height: 15,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                "交易品种",
                style: TextStyle(color: c_999999, fontSize: 12),
              ),
              Text(
                "交易量(手数)",
                style: TextStyle(color: c_999999, fontSize: 12),
              ),
              Text(
                "交易价格(USD)",
                style: TextStyle(color: c_999999, fontSize: 12),
              ),
            ],
          ),
          SizedBox(
            height: 5,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                bean.symbol ?? "",
                style: TextStyle(color: c_333333, fontSize: 14),
              ),
              Text(
                bean.volumeTxt.toString() ?? "",
                style: TextStyle(color: c_333333, fontSize: 14),
              ),
              Text(
                bean.price ?? "",
                style: TextStyle(color: c_333333, fontSize: 14),
              ),
            ],
          ),
          SizedBox(
            height: 10,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                "手续费(USD)",
                style: TextStyle(color: c_999999, fontSize: 12),
              ),
              Text(
                "隔夜利息(USD)",
                style: TextStyle(color: c_999999, fontSize: 12),
              ),
              Text(
                "盈亏(USD)",
                style: TextStyle(color: c_999999, fontSize: 12),
              ),
            ],
          ),
          SizedBox(
            height: 5,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                bean.priceTp ?? "",
                style: TextStyle(color: c_333333, fontSize: 14),
              ),
              Text(
                bean.storage ?? "",
                style: TextStyle(color: c_333333, fontSize: 14),
              ),
              Text(
                bean.profit ?? "",
                style: TextStyle(color: c_333333, fontSize: 14),
              ),
            ],
          ),
          SizedBox(
            height: 10,
          ),
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                "时间",
                style: TextStyle(color: c_999999, fontSize: 12),
              ),
              SizedBox(
                height: 5,
              ),
              Text(
                AppUtils.dateToString(bean.timeAt),
                style: TextStyle(color: c_333333, fontSize: 14),
              ),
            ],
          )
        ],
      ),
    );
  }
}
